package net.lanelife.casino.cms.web.controller;

import net.lanelife.casino.caipiao.dto.admin.UserLayerCreateDTO;
import net.lanelife.casino.caipiao.dto.admin.UserLayerDTO;
import net.lanelife.casino.caipiao.dto.admin.UserLayerTable;
import net.lanelife.casino.caipiao.dto.admin.UserLayerUpdateDTO;
import net.lanelife.casino.caipiao.entity.UserLayer;
import net.lanelife.casino.caipiao.service.api.IUserLayerService;
import net.lanelife.casino.cms.web.controller.support.CRUDController;
import net.lanelife.casino.common.service.support.IGenericService;
import net.lanelife.casino.common.web.resolver.ViewResolver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = UserLayerController.PATH)
public class UserLayerController extends CRUDController<UserLayer, Integer, UserLayerDTO, UserLayerCreateDTO, UserLayerUpdateDTO, UserLayerTable<UserLayerDTO>> {
	
	public static final String PATH = "/user-layer";
	
	public UserLayerController() {
		super(PATH);
	}

	@Autowired
	private IUserLayerService userLayerService;
	
	@Override
	protected IGenericService<UserLayer, Integer> getService() {
		return userLayerService;
	}
	
	@RequestMapping(value = { "/set-as-default/{id}" }, method = RequestMethod.GET)
	public String setAsDefault(@PathVariable Integer id) throws Exception {
		userLayerService.setAsDefault(id);
		return ViewResolver.getView(PATH + "/list");
	}
	
	@RequestMapping(value = { "/count-users" }, method = RequestMethod.GET)
	public String countUsers() throws Exception {
		userLayerService.countUsers();
		return ViewResolver.getView(PATH + "/list");
	}

}
